home *** CD-ROM | disk | FTP | other *** search
/ Freelog 121 / FreelogMagazineJuilletAout2014-No121.iso / Outils / Adobe-Air / adobe-air_13.exe / [0] / setup.swf / scripts / mx / containers / utilityClasses / Flex.as < prev    next >
Text File  |  2014-03-27  |  12KB  |  359 lines

  1. package mx.containers.utilityClasses
  2. {
  3.    import mx.core.Container;
  4.    import mx.core.FlexVersion;
  5.    import mx.core.IUIComponent;
  6.    import mx.core.mx_internal;
  7.    
  8.    use namespace mx_internal;
  9.    
  10.    public class Flex
  11.    {
  12.       
  13.       mx_internal static const VERSION:String = "3.0.0.0";
  14.        
  15.       
  16.       public function Flex()
  17.       {
  18.          super();
  19.       }
  20.       
  21.       public static function flexChildWidthsProportionally(param1:Container, param2:Number, param3:Number) : Number
  22.       {
  23.          var _loc6_:Array = null;
  24.          var _loc7_:FlexChildInfo = null;
  25.          var _loc8_:IUIComponent = null;
  26.          var _loc9_:int = 0;
  27.          var _loc11_:Number = NaN;
  28.          var _loc12_:Number = NaN;
  29.          var _loc13_:Number = NaN;
  30.          var _loc14_:Number = NaN;
  31.          var _loc4_:Number = param2;
  32.          var _loc5_:Number = 0;
  33.          _loc6_ = [];
  34.          var _loc10_:int = param1.numChildren;
  35.          _loc9_ = 0;
  36.          while(_loc9_ < _loc10_)
  37.          {
  38.             _loc11_ = (_loc8_ = IUIComponent(param1.getChildAt(_loc9_))).percentWidth;
  39.             _loc12_ = _loc8_.percentHeight;
  40.             if(!isNaN(_loc12_) && _loc8_.includeInLayout)
  41.             {
  42.                _loc13_ = Math.max(_loc8_.minHeight,Math.min(_loc8_.maxHeight,_loc12_ >= 100 ? Number(param3) : Number(param3 * _loc12_ / 100)));
  43.             }
  44.             else
  45.             {
  46.                _loc13_ = _loc8_.getExplicitOrMeasuredHeight();
  47.             }
  48.             if(!isNaN(_loc11_) && _loc8_.includeInLayout)
  49.             {
  50.                _loc5_ += _loc11_;
  51.                (_loc7_ = new FlexChildInfo()).percent = _loc11_;
  52.                _loc7_.min = _loc8_.minWidth;
  53.                _loc7_.max = _loc8_.maxWidth;
  54.                _loc7_.height = _loc13_;
  55.                _loc7_.child = _loc8_;
  56.                _loc6_.push(_loc7_);
  57.             }
  58.             else
  59.             {
  60.                _loc14_ = _loc8_.getExplicitOrMeasuredWidth();
  61.                if(_loc8_.scaleX == 1 && _loc8_.scaleY == 1)
  62.                {
  63.                   _loc8_.setActualSize(Math.floor(_loc14_),Math.floor(_loc13_));
  64.                }
  65.                else
  66.                {
  67.                   _loc8_.setActualSize(_loc14_,_loc13_);
  68.                }
  69.                if(_loc8_.includeInLayout)
  70.                {
  71.                   _loc4_ -= _loc8_.width;
  72.                }
  73.             }
  74.             _loc9_++;
  75.          }
  76.          if(_loc5_)
  77.          {
  78.             _loc4_ = flexChildrenProportionally(param2,_loc4_,_loc5_,_loc6_);
  79.             _loc10_ = _loc6_.length;
  80.             _loc9_ = 0;
  81.             while(_loc9_ < _loc10_)
  82.             {
  83.                if((_loc8_ = (_loc7_ = _loc6_[_loc9_]).child).scaleX == 1 && _loc8_.scaleY == 1)
  84.                {
  85.                   _loc8_.setActualSize(Math.floor(_loc7_.size),Math.floor(_loc7_.height));
  86.                }
  87.                else
  88.                {
  89.                   _loc8_.setActualSize(_loc7_.size,_loc7_.height);
  90.                }
  91.                _loc9_++;
  92.             }
  93.             if(FlexVersion.compatibilityVersion >= FlexVersion.VERSION_3_0)
  94.             {
  95.                distributeExtraWidth(param1,param2);
  96.             }
  97.          }
  98.          return _loc4_;
  99.       }
  100.       
  101.       public static function distributeExtraHeight(param1:Container, param2:Number) : void
  102.       {
  103.          var _loc5_:int = 0;
  104.          var _loc6_:Number = NaN;
  105.          var _loc9_:IUIComponent = null;
  106.          var _loc10_:Number = NaN;
  107.          var _loc11_:Number = NaN;
  108.          var _loc3_:int = param1.numChildren;
  109.          var _loc4_:Boolean = false;
  110.          var _loc7_:Number = param2;
  111.          var _loc8_:Number = 0;
  112.          _loc5_ = 0;
  113.          while(_loc5_ < _loc3_)
  114.          {
  115.             if((_loc9_ = IUIComponent(param1.getChildAt(_loc5_))).includeInLayout)
  116.             {
  117.                _loc10_ = _loc9_.height;
  118.                _loc6_ = _loc9_.percentHeight;
  119.                _loc8_ += _loc10_;
  120.                if(!isNaN(_loc6_))
  121.                {
  122.                   if((_loc11_ = Math.ceil(_loc6_ / 100 * param2)) > _loc10_)
  123.                   {
  124.                      _loc4_ = true;
  125.                   }
  126.                }
  127.             }
  128.             _loc5_++;
  129.          }
  130.          if(!_loc4_)
  131.          {
  132.             return;
  133.          }
  134.          _loc7_ -= _loc8_;
  135.          var _loc12_:Boolean = true;
  136.          while(_loc12_ && _loc7_ > 0)
  137.          {
  138.             _loc12_ = false;
  139.             _loc5_ = 0;
  140.             while(_loc5_ < _loc3_)
  141.             {
  142.                _loc10_ = (_loc9_ = IUIComponent(param1.getChildAt(_loc5_))).height;
  143.                _loc6_ = _loc9_.percentHeight;
  144.                if(!isNaN(_loc6_) && _loc9_.includeInLayout && _loc10_ < _loc9_.maxHeight)
  145.                {
  146.                   if((_loc11_ = Math.ceil(_loc6_ / 100 * param2)) > _loc10_)
  147.                   {
  148.                      _loc9_.setActualSize(_loc9_.width,_loc10_ + 1);
  149.                      _loc7_--;
  150.                      _loc12_ = true;
  151.                      if(_loc7_ == 0)
  152.                      {
  153.                         return;
  154.                      }
  155.                   }
  156.                }
  157.                _loc5_++;
  158.             }
  159.          }
  160.       }
  161.       
  162.       public static function distributeExtraWidth(param1:Container, param2:Number) : void
  163.       {
  164.          var _loc5_:int = 0;
  165.          var _loc6_:Number = NaN;
  166.          var _loc9_:IUIComponent = null;
  167.          var _loc10_:Number = NaN;
  168.          var _loc11_:Number = NaN;
  169.          var _loc3_:int = param1.numChildren;
  170.          var _loc4_:Boolean = false;
  171.          var _loc7_:Number = param2;
  172.          var _loc8_:Number = 0;
  173.          _loc5_ = 0;
  174.          while(_loc5_ < _loc3_)
  175.          {
  176.             if((_loc9_ = IUIComponent(param1.getChildAt(_loc5_))).includeInLayout)
  177.             {
  178.                _loc10_ = _loc9_.width;
  179.                _loc6_ = _loc9_.percentWidth;
  180.                _loc8_ += _loc10_;
  181.                if(!isNaN(_loc6_))
  182.                {
  183.                   if((_loc11_ = Math.ceil(_loc6_ / 100 * param2)) > _loc10_)
  184.                   {
  185.                      _loc4_ = true;
  186.                   }
  187.                }
  188.             }
  189.             _loc5_++;
  190.          }
  191.          if(!_loc4_)
  192.          {
  193.             return;
  194.          }
  195.          _loc7_ -= _loc8_;
  196.          var _loc12_:Boolean = true;
  197.          while(_loc12_ && _loc7_ > 0)
  198.          {
  199.             _loc12_ = false;
  200.             _loc5_ = 0;
  201.             while(_loc5_ < _loc3_)
  202.             {
  203.                _loc10_ = (_loc9_ = IUIComponent(param1.getChildAt(_loc5_))).width;
  204.                _loc6_ = _loc9_.percentWidth;
  205.                if(!isNaN(_loc6_) && _loc9_.includeInLayout && _loc10_ < _loc9_.maxWidth)
  206.                {
  207.                   if((_loc11_ = Math.ceil(_loc6_ / 100 * param2)) > _loc10_)
  208.                   {
  209.                      _loc9_.setActualSize(_loc10_ + 1,_loc9_.height);
  210.                      _loc7_--;
  211.                      _loc12_ = true;
  212.                      if(_loc7_ == 0)
  213.                      {
  214.                         return;
  215.                      }
  216.                   }
  217.                }
  218.                _loc5_++;
  219.             }
  220.          }
  221.       }
  222.       
  223.       public static function flexChildrenProportionally(param1:Number, param2:Number, param3:Number, param4:Array) : Number
  224.       {
  225.          var _loc6_:Number = NaN;
  226.          var _loc7_:Boolean = false;
  227.          var _loc9_:* = undefined;
  228.          var _loc10_:* = undefined;
  229.          var _loc11_:* = undefined;
  230.          var _loc12_:* = undefined;
  231.          var _loc13_:* = undefined;
  232.          var _loc14_:* = undefined;
  233.          var _loc5_:int = param4.length;
  234.          var _loc8_:Number;
  235.          if((_loc8_ = param2 - param1 * param3 / 100) > 0)
  236.          {
  237.             param2 -= _loc8_;
  238.          }
  239.          do
  240.          {
  241.             _loc6_ = 0;
  242.             _loc7_ = true;
  243.             _loc9_ = param2 / param3;
  244.             _loc10_ = 0;
  245.             while(_loc10_ < _loc5_)
  246.             {
  247.                if((_loc12_ = (_loc11_ = param4[_loc10_]).percent * _loc9_) < _loc11_.min)
  248.                {
  249.                   _loc13_ = _loc11_.min;
  250.                   _loc11_.size = _loc13_;
  251.                   param4[_loc10_] = param4[--_loc5_];
  252.                   param4[_loc5_] = _loc11_;
  253.                   param3 -= _loc11_.percent;
  254.                   param2 -= _loc13_;
  255.                   _loc7_ = false;
  256.                   break;
  257.                }
  258.                if(_loc12_ > _loc11_.max)
  259.                {
  260.                   _loc14_ = _loc11_.max;
  261.                   _loc11_.size = _loc14_;
  262.                   param4[_loc10_] = param4[--_loc5_];
  263.                   param4[_loc5_] = _loc11_;
  264.                   param3 -= _loc11_.percent;
  265.                   param2 -= _loc14_;
  266.                   _loc7_ = false;
  267.                   break;
  268.                }
  269.                _loc11_.size = _loc12_;
  270.                _loc6_ += _loc12_;
  271.                _loc10_++;
  272.             }
  273.          }
  274.          while(!_loc7_);
  275.          
  276.          return Math.max(0,Math.floor(param2 - _loc6_));
  277.       }
  278.       
  279.       public static function flexChildHeightsProportionally(param1:Container, param2:Number, param3:Number) : Number
  280.       {
  281.          var _loc7_:FlexChildInfo = null;
  282.          var _loc8_:IUIComponent = null;
  283.          var _loc9_:int = 0;
  284.          var _loc11_:Number = NaN;
  285.          var _loc12_:Number = NaN;
  286.          var _loc13_:Number = NaN;
  287.          var _loc14_:Number = NaN;
  288.          var _loc4_:Number = param2;
  289.          var _loc5_:Number = 0;
  290.          var _loc6_:Array = [];
  291.          var _loc10_:int = param1.numChildren;
  292.          _loc9_ = 0;
  293.          while(_loc9_ < _loc10_)
  294.          {
  295.             _loc11_ = (_loc8_ = IUIComponent(param1.getChildAt(_loc9_))).percentWidth;
  296.             _loc12_ = _loc8_.percentHeight;
  297.             if(!isNaN(_loc11_) && _loc8_.includeInLayout)
  298.             {
  299.                _loc13_ = Math.max(_loc8_.minWidth,Math.min(_loc8_.maxWidth,_loc11_ >= 100 ? Number(param3) : Number(param3 * _loc11_ / 100)));
  300.             }
  301.             else
  302.             {
  303.                _loc13_ = _loc8_.getExplicitOrMeasuredWidth();
  304.             }
  305.             if(!isNaN(_loc12_) && _loc8_.includeInLayout)
  306.             {
  307.                _loc5_ += _loc12_;
  308.                (_loc7_ = new FlexChildInfo()).percent = _loc12_;
  309.                _loc7_.min = _loc8_.minHeight;
  310.                _loc7_.max = _loc8_.maxHeight;
  311.                _loc7_.width = _loc13_;
  312.                _loc7_.child = _loc8_;
  313.                _loc6_.push(_loc7_);
  314.             }
  315.             else
  316.             {
  317.                _loc14_ = _loc8_.getExplicitOrMeasuredHeight();
  318.                if(_loc8_.scaleX == 1 && _loc8_.scaleY == 1)
  319.                {
  320.                   _loc8_.setActualSize(Math.floor(_loc13_),Math.floor(_loc14_));
  321.                }
  322.                else
  323.                {
  324.                   _loc8_.setActualSize(_loc13_,_loc14_);
  325.                }
  326.                if(_loc8_.includeInLayout)
  327.                {
  328.                   _loc4_ -= _loc8_.height;
  329.                }
  330.             }
  331.             _loc9_++;
  332.          }
  333.          if(_loc5_)
  334.          {
  335.             _loc4_ = flexChildrenProportionally(param2,_loc4_,_loc5_,_loc6_);
  336.             _loc10_ = _loc6_.length;
  337.             _loc9_ = 0;
  338.             while(_loc9_ < _loc10_)
  339.             {
  340.                if((_loc8_ = (_loc7_ = _loc6_[_loc9_]).child).scaleX == 1 && _loc8_.scaleY == 1)
  341.                {
  342.                   _loc8_.setActualSize(Math.floor(_loc7_.width),Math.floor(_loc7_.size));
  343.                }
  344.                else
  345.                {
  346.                   _loc8_.setActualSize(_loc7_.width,_loc7_.size);
  347.                }
  348.                _loc9_++;
  349.             }
  350.             if(FlexVersion.compatibilityVersion >= FlexVersion.VERSION_3_0)
  351.             {
  352.                distributeExtraHeight(param1,param2);
  353.             }
  354.          }
  355.          return _loc4_;
  356.       }
  357.    }
  358. }
  359.